/*
 * ForceHMF.c
 *
 *  Created on: 10/08/2012
 *      Author: joserobertosteiner
 */

#include <stdlib.h>
#include <math.h>

int ForceHMF(long nmax, double *magx, double *magy, double r[], double f[]){

	long i;
	double aux1, aux2;
	double cc[nmax], ss[nmax];

	for(i = 0 ; i < nmax ; i++){
		aux1 = sin(r[i]);
		aux2 = cos(r[i]);
		*magx += aux2;
		*magy += aux1;
		cc[i] = aux2;
		ss[i] = aux1;
	}

	*magx = *magx/((double) nmax);
	*magy = *magy/((double) nmax);

	for (i = 0; i < nmax; ++i) {
		f[i] = cc[i]*(*magy) - ss[i]*(*magx);
	}

	return EXIT_SUCCESS;
}
